import api from './index'

// 获取角色列表
export const getRoles = (params?: { page?: number; page_size?: number }) => {
  return api.get('/role', { params })
}

// 获取角色详情
export const getRoleById = (id: number) => {
  return api.get(`/role/${id}`)
}

// 创建角色
export const createRole = (data: any) => {
  return api.post('/role', data)
}

// 更新角色
export const updateRole = (id: number, data: any) => {
  return api.put(`/role/${id}`, data)
}

// 删除角色
export const deleteRole = (id: number) => {
  return api.delete(`/role/${id}`)
}

// 获取角色下的管理员
export const getRoleAdmins = (id: number) => {
  return api.get(`/role/${id}/admins`)
}

// 分配角色给管理员
export const assignRoleToAdmin = (admin_id: number, role_id: number) => {
  return api.post('/role/assign', null, {
    params: { admin_id, role_id }
  })
}

// 移除管理员的角色
export const removeRoleFromAdmin = (admin_id: number, role_id: number) => {
  return api.delete('/role/remove', {
    params: { admin_id, role_id }
  })
}